package com.yc.cloudvideo.sp_store.mapper;

import com.yc.cloudvideo.entity.Store;
import com.yc.cloudvideo.entity.StoreUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.cloudvideo.entity.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LYYT
 * @since 2022-08-03
 */
public interface StoreUserMapper extends BaseMapper<StoreUser> {
    //查询自建仓库信息
    @Select("select * from store_user where uid=#{uid} and level=1")
    @Results({
            //MyBatis 默认字段映射只能映射一次
            @Result(property = "cid",column ="cid"),
            @Result(property = "store",column ="cid",
                    one = @One(select="selectStoreByCid"))
    })
    List<StoreUser> selectMystoreByUid(int uid);
    //查询其他仓库信息
    @Select("select * from store_user where uid=#{uid} and level between 2 and 4")
    @Results({
            //MyBatis 默认字段映射只能映射一次
            @Result(property = "cid",column ="cid"),
            @Result(property = "store",column ="cid",
                    one = @One(select="selectStoreByCid"))
    })
    List<StoreUser> selectOtherstoreByUid(int uid);

    //查询仓库
    @Select("select * from store where cid=#{cid}")
    @Results({
            //MyBatis 默认字段映射只能映射一次
            @Result(property = "cid",column ="cid"),
            @Result(property = "user",column ="cid",
                    one = @One(select="selectByCid"))
    })
    Store selectStoreByCid(int cid);

    //查询创建者信息
    @Select("select u.* from store_user s join user u on s.uid=u.uid where cid=#{cid}  and level=1")
    User selectByCid(int cid);
    @Select("select u.* from store_user s join user u on s.uid=u.uid where cid=#{cid}  and level>1")
    User selectOtherByCid(int cid);
}
